package cn.hx.admin.controller;

import cn.hx.admin.entity.Province;
import cn.hx.admin.service.ProvinceService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
/**
 * 省份(Province)表控制层
 *
 * @author makejava
 * @since 2023-12-13 14:47:19
 */
@RestController
@RequestMapping("province")
public class ProvinceController {
    /**
     * 服务对象
     */
    @Resource
    private ProvinceService provinceService;

    /**
     * 分页查询
     *
     * @param province 筛选条件
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<List<Province>> queryByPage(Province province) {
        return ResponseEntity.ok(this.provinceService.queryByPage(province));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Province> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.provinceService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param province 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Province> add(Province province) {
        return ResponseEntity.ok(this.provinceService.insert(province));
    }

    /**
     * 编辑数据
     *
     * @param province 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Province> edit(Province province) {
        return ResponseEntity.ok(this.provinceService.update(province));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.provinceService.deleteById(id));
    }

}

